package com.example.firstopengl;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import static android.R.attr.id;

/**
 * Created by liqian-ps on 2017/6/27.
 */

public class TextResourceReader {


    public static String readTextFileFromResource(Context context, int resourceId) {

        StringBuffer stringBuffer = new StringBuffer();

        try {
            InputStream inputStream = context.getResources().openRawResource(resourceId);

            InputStreamReader streamReader = new InputStreamReader(inputStream);

            BufferedReader bufferedReader = new BufferedReader(streamReader);

            String nextLine;
            while ((nextLine = bufferedReader.readLine()) != null) {
                stringBuffer.append(nextLine);
                stringBuffer.append("\n");
            }
        } catch (IOException e) {

        }

        return stringBuffer.toString();
    }
}
